import http from './interface'

/**
 * 将业务所有接口统一起来便于维护
 * 如果项目很大可以将 url 独立成文件，接口分成不同的模块
 * 
 */



// uni.setStorageSync('token', "a77ee00d-30de-4ecf-8987-7b6b811c6b61");

//设置baseUrl
// http.config.baseUrl = "http://192.168.1.100:8000/webapi"
// http.config.baseUrl = "http://192.168.1.10:8000/webapi"

// http.config.baseUrl = "https://allblink.com/webapi"
//设置请求前拦截器
http.interceptor.request = (configs) => {
	//添加通用参数
	configs.header = {
		"token": uni.getStorageSync('token'),
		// "versionCode": config.versionCode
	}
}
//设置请求结束后拦截器
http.interceptor.response = (response) => {
	//判断返回状态 执行相应操作
	// if (response.config.url.endsWith('/user/auth/') && response.config.method == 'POST') {
	// 	uni.setStorageSync('token', response.data.data.token);
	// }
	return response;
}



const apis = {
	// test: (data) => {
	// 	return http.request({
	// 		url: '/user/login/',
	// 		data,
	// 	})
	// },

	login: (data) => {
		return http.request({
			url: '/user/login/',
			method: 'POST',
			data,
		})
	},
	getGoods: (data) => {
		return http.request({
			url: '/shop/user/goods/',
			method: 'get',
			data,
		})
	},
	addAddress: (data) => {
		return http.request({
			url: '/shop/add/address/',
			method: 'post',
			data,
		})
	},
	getAddress: (data) => {
		return http.request({
			url: '/shop/address/',
			method: 'get',
			data,
		})
	},
	addOrder: (data) => {
		return http.request({
			url: '/shop/add/order/',
			method: 'post',
			data,
		})
	},
	getOrderList: (data) => {
		return http.request({
			url: '/shop/order/list/',
			method: 'get',
			data,
		})
	},

}


export default apis
